// Copyright 2008 web2me.dev
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package net.web2me.gui;

import javax.swing.JTextArea;

import net.web2me.api.CommonConstants;

import org.apache.log4j.Appender;
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;

/**
 * Displays the {@link Logger} messages into a {@link JTextArea}.
 * 
 * @author web2me
 *
 */
public class JTextAreaAppender implements Appender {
	
	private JTextArea area;
	
	private String name = "JTextFieldAppender";
	
	private Layout layout;
	
	private ErrorHandler errorHandler;
	
	public JTextAreaAppender() {
		area = Web2MeGuiSwing.getLoggerTextField();
		area.setText(CommonConstants.EMPTY);
	}

	public void addFilter(Filter filter) {

	}

	public void clearFilters() {

	}

	public void close() {

	}

	public void doAppend(LoggingEvent e) {
		area.setText(area.getText() + e.getMessage() + CommonConstants.NEW_LINE);
	}

	public ErrorHandler getErrorHandler() {
		return errorHandler;
	}

	public Filter getFilter() {
		return null;
	}

	public Layout getLayout() {
		return layout;
	}

	public String getName() {
		return name;
	}

	public boolean requiresLayout() {
		return true;
	}

	public void setErrorHandler(ErrorHandler errorHandler) {
		this.errorHandler = errorHandler;
	}

	public void setLayout(Layout layout) {
		this.layout = layout;
	}

	public void setName(String name) {
		this.name = name;
	}

}
